/*!
 * \file test_http.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include <frservice_mng.h>

#include "t_frct_comm/t_frct_comm.h"
#include "t_frdb_cursor/t_frdb_cursor.h"
#include "t_frexp_comm/t_frexp_comm.h"
#include "t_frreport_comm/t_frreport_comm.h"
#include "t_frreport_session_comm/t_frreport_session_comm.h"
#include "t_frservice_comm/t_frservice_comm.h"
#include "t_frtds_convert/t_frtds_convert.h"
#include "t_frct_detect_hash/t_frct_detect_hash.h"
#include "t_frhessian/t_frhessian.h"
#include "t_frkyro/t_frkyro.h"
#include "t_frrmi/t_frrmi.h"
#include "t_serialize_hessian2/t_serialize_hessian2.h"

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

void add_suites(FunType *p_func, int i_suites_len, FunType fp)
{
    int i_loop = 0;
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (p_func[i_loop] == NULL)
        {
            p_func[i_loop] = fp;
            break;
        }
    }
}

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, "apmcomm") == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    // t_frct_comm
    add_suites(fun_suites, i_suites_len, add_suite_frcap_get_cs_direction);
    add_suites(fun_suites, i_suites_len, add_suite_frcap_set_cs_srv);
    add_suites(fun_suites, i_suites_len, add_suite_frct_get_L7transaction);
    add_suites(fun_suites, i_suites_len, add_suite_frct_get_session);
    add_suites(fun_suites, i_suites_len, add_suite_frct_get_session_private);
    add_suites(fun_suites, i_suites_len, add_suite_frct_get_session_starttime);
    add_suites(fun_suites, i_suites_len, add_suite_frct_get_session_status);
    add_suites(fun_suites, i_suites_len, add_suite_frct_get_session_stoptime);
    add_suites(fun_suites, i_suites_len, add_suite_frct_set_session_private);
    add_suites(fun_suites, i_suites_len, add_suite_frct_set_session_starttime);
    add_suites(fun_suites, i_suites_len, add_suite_frct_set_session_status);
    add_suites(fun_suites, i_suites_len, add_suite_frct_set_session_stoptime);
    add_suites(fun_suites, i_suites_len, add_suite_frct_set_session_username);

    //t_frdb_cursor
    add_suites(fun_suites, i_suites_len, add_suite___frdb_get_interval_time);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_add_metadata_info);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_add_resultset);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_add_resultset_bind);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_del_specified_resultset);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_frlist_copy);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_get_first_metadata);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_get_last_resultset);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_get_specified_metadata);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_get_specified_resultset);
    add_suites(fun_suites, i_suites_len, add_suite_frdb_title_value_chg);

    //t_frexp_comm
    add_suites(fun_suites, i_suites_len, add_suite___frexpect_add);
    add_suites(fun_suites, i_suites_len, add_suite_frexpect_hash_key);

    // t_frreport_comm
    add_suites(fun_suites, i_suites_len, add_suite___frreport_data_new);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_bin);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_double);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_float);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_int);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_long);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_str);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_str_limit);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_timeval);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_uint);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7_add_ulong);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_l7list_clone);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_new_stat_conn);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_body_new_stat_port);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_set_agent_from);
    add_suites(fun_suites, i_suites_len, add_suite_frreport_set_body_len);

    //t_frreport_session_comm
    add_suites(fun_suites, i_suites_len, add_suite_frreport_session_comm);

    //t_frservice_comm
    add_suites(fun_suites, i_suites_len, add_suite_frservice_get);

    //t_frtds_convert
    add_suites(fun_suites, i_suites_len, add_suite___frtds_binary_to_double);
    add_suites(fun_suites, i_suites_len, add_suite___frtds_binary_to_float);
    add_suites(fun_suites, i_suites_len, add_suite___frtds_days_fromat);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_boolean);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_booleann);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_date);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_daten);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_datetimen);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_float);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_floatn);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_int);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_intn);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_money);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_mssql_timen);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_time);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_timen);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_convert_to_varchar);
    add_suites(fun_suites, i_suites_len, add_suite_frtds_get_datetimes);

    //t_frct_detect_hash
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_hash_init);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_hash_key);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_hash_key_add);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_hash_add);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_data_get_node);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_data_get);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_data_update);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_hash_del);
    add_suites(fun_suites, i_suites_len, add_suite_frct_detect_hash_del_node);

    //t_frhessian
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_read_call);
    add_suites(fun_suites, i_suites_len, add_suite___frhessian_parse_utf8);
    add_suites(fun_suites, i_suites_len, add_suite___frhessian_parse_char);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_read_head);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_read_method);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_double);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_int);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_long);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_string);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_bytes);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_read_type);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_date);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_list);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_map);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian_get_type);

    //t_frkyro
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_ascii);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_utf8);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_string);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_var_int);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_var_long);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_float);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_double);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_short);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_int);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_char);
    add_suites(fun_suites, i_suites_len, add_suite_frkyro_read_byte);

    //t_frrmi
    add_suites(fun_suites, i_suites_len, add_suite_skipCustomData);
    add_suites(fun_suites, i_suites_len, add_suite_readUTF);
    add_suites(fun_suites, i_suites_len, add_suite_readStreamHeader);
    add_suites(fun_suites, i_suites_len, add_suite_readNull);
    add_suites(fun_suites, i_suites_len, add_suite_readHandle);
    add_suites(fun_suites, i_suites_len, add_suite_readBlockHeader);
    add_suites(fun_suites, i_suites_len, add_http_rmi_detect);

    //t_serialize_hessian2
    add_suites(fun_suites, i_suites_len, add_suite__serialize_hessian2_readint);
    add_suites(fun_suites, i_suites_len, add_suite__serialize_hessian2_readstring);
    add_suites(fun_suites, i_suites_len, add_suite__serialize_hessian2_readtype);
    add_suites(fun_suites, i_suites_len, add_suite_serialize_hessian2_readobject);
    add_suites(fun_suites, i_suites_len, add_suite_serialize_hessian2_readcall);
    add_suites(fun_suites, i_suites_len, add_suite_serialize_hessian2_readcall1);
    add_suites(fun_suites, i_suites_len, add_suite_serialize_hessian2_readreply);
    add_suites(fun_suites, i_suites_len, add_suite_frhessian2_resp_read);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();
    fr_slab_destroy();

    return 0;
}
